<%@page import="user.UserDao"%>
<%@page import="user.User"%>
<%@page import="java.security.Timestamp"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.Iterator"%>
<%@page import="news.News"%>
<%@page import="java.util.ArrayList"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新闻查询</title>
<script type="text/javascript">
	window.onload = function color() {//窗口加载时调用  
		var table = document.getElementById("table");//根据table的 id 属性值获得对象  
		var rows = table.getElementsByTagName("tr");//获取table类型的tr元素的列表  
		for (var i = 1; i < rows.length; i++) {
			if (i % 2 == 0) {
				rows[i].style.backgroundColor = "red";//偶数行时背景色为#EAF2D3  
			} else {
				rows[i].style.backgroundColor = "green";//单数行时背景色为white  
			}
		}
	}
</script>
</head>

<style>
* {
	margin: 0;
	padding: 0;
}
body{
  background-image: url(../images/1.png);
}
table {
	margin: 30px 20%;
}

.Qresult {
	margin: 100px 15%;
	
}

.Qresult th {
	background-color: #00f317;
}

.Qresult td {
	background-color: #00f2c8;
}

th, td {
	padding: 5px;
}

.tt {
	background-color: #00fff7;
}

.ti {
	background-color: #00ff4a;
}

.bt {
	letter-spacing: 2em;
	padding: 5px 0 5px 2em;
	margin: 10px 35%;
}

input[type=text] {
	height: 1.5em;
}

.show {
	display: block;
	width: 150px;
	text-overflow: ellipsis;
	overflow: hidden;
	white-space: nowrap;
}

.show:hover {
    width:420px;
	overflow: auto;
	white-space: normal;
}

.topview {
	margin-bottom: 20px;
}

.theme {
	font-family: "STLiti";
	margin-left: 120px;
	font-size: 40px;
	margin-right: 50px;
	text-shadow: 1px 1px 5px red, 1px 1px 5px orange;
}

.fr {
	position: absolute;
	left: 350px;
	top: 20px;
}

.find {
	width: 400px;
	height: 30px;
	border: 1px solid blue;
	border-radius: 15px;
}

.findbtn {
	margin-left: 20px;
	width: 80px;
	height: 30px;
	border: 1px solid #000000;
	border-radius: 15px;
	background-image: linear-gradient(to right, #84fab0, #8fd3f4);
}
a{
text-decoration:none;
}
</style>
<body>
  
    <form action="../ServletNewsQuery" target="" class="fr">
		<input type="text" name="title" placeholder="请输入想要查找的新闻" class="find">
		<input type="submit" value="快速搜索" class="findbtn">
	</form>
	
	<table class="Qresult">
	
	<tr>
			<th>新闻编号</th>
			<th>新闻标题</th>
			<th>发布人</th>
			<th>发布时间</th>
			<th>操作</th>
		</tr>
		<tr>	
		<%
		//从session中获取查询结果
		ArrayList<News> list= (ArrayList<News>) request.getSession().getAttribute("list");
	    User user = (User)request.getSession().getAttribute("user");
		//是否已执行过查询
		boolean queried = list != null;
		if (queried) {
			Iterator<News> iterator = list.iterator();		
		   while(iterator.hasNext()){
			News news = iterator.next();
			%>
			<td><%=news.getNid()%></td>
			<td class="show" title="${msgContent}"><%=news.getTitle()%></td>
			<td><%=news.getUname()%></td>
			<td><fmt:formatDate value="${news.getPubtime()}" pattern="yyyy-MM-dd HH:MM:dd"/></td>
			<td><a href="../ServletNewsList?nid=<%=news.getNid()%>">查看</a> 
			<%
			if(news.getUid()==user.getUid()){
				
				%>
			<a href="./news_Modify.jsp?nid=<%=news.getNid()%>">修改</a> 
			<a href="../News_delete?nid=<%=news.getNid()%>" onclick="return reallyDel('<%=news.getNid()%>');">删除</a></td>
			<% 
			}
			%>
		</tr>
	
	<%
		request.getSession().removeAttribute("queryResult");
		}
		}
	%>
	</table>
</body>
<script type="text/javascript">
	function reallyDel(titi) {
		var hint = "确认要删除新闻:“" + titi + "”？";
		var jg = confirm(hint);
		if (jg) {
			return true;
		}
		return false;
	}
</script>
</html>